// pages/index/newIndex.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMG_NAME: app.IMG_NAME,
    parkName: '',
    tabBarList: [{
        "pagePath": "pages/index/newIndex/newIndex",
        "iconPath": "/images/tabbar/home.png",
        "selectedIconPath": "/images/tabbar/home-select.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/meeting/meetingReservation/meetingReservation",
        "iconPath": "/images/tabbar/openDoor.png",
        "selectedIconPath": "/images/tabbar/openDoor.png",
        "text": "预约",
        "bulge": true,
      },
      {
        "pagePath": "pages/my/my",
        "iconPath": "/images/tabbar/my.png",
        "selectedIconPath": "/images/tabbar/my-select.png",
        "text": "我的"
      }
    ],
    tabBarParam: {
      color: "#999999",
      selectedColor: "#1989FA",
      selected: 0
    }
  },

  /**
   * 导航到会议预约页面
   */
  navigateToMeetingReservation: function () {
    wx.navigateTo({
      url: '/pages/meeting/meetingReservation/meetingReservation',
    });
  },

  /**
   * 导航到会议记录页面
   */
  navigateToMeetingRecord: function () {
    wx.navigateTo({
      url: '/pages/meeting/reservationRecord/reservationRecord',
    });
  },

  // 切换tabbar
  switchTab(e) {
    const data = e.currentTarget.dataset
    const index = e.currentTarget.dataset.index
    console.log('switchTab', data);
    const url = data.path
    if(index == 1){
      wx.navigateTo({
        url: '/' + url
      });
    }else{
      wx.switchTab({
        url: '/' + url
      })
    }

  },

  /**
   * 导航到园区列表
   */
  navparkList: function () {
    wx.navigateTo({
      url: '/pages/parkList/parkList',
    });
  },

  /**
   * 跳转到园区
   */
  jumpPark: function () {
    console.log(111);
    if (!this.data.parkName) {
      this.navparkList();
    }
  },

  /**
   * 扫码功能
   */
  jumpScan: function () {
    wx.scanCode({
      success: (res) => {
        console.log('扫码结果:', res);
        // 处理扫码结果，可根据实际需求进行跳转或其他操作
        wx.showToast({
          title: '扫码成功',
          icon: 'success'
        });
      },
      fail: (err) => {
        console.error('扫码失败:', err);
        wx.showToast({
          title: '扫码失败',
          icon: 'error'
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 获取存储的园区名称
    const parkName = wx.getStorageSync('parkName');
    if (parkName) {
      this.setData({
        parkName
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 检查是否有更新的园区名称
    const parkName = wx.getStorageSync('parkName');
    if (parkName && parkName !== this.data.parkName) {
      this.setData({
        parkName
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})